#include <iostream>  
#include <stack>  
using namespace std;  
  
const int MAXN = 100;  
int n;  
int col[MAXN],
    queen[MAXN], 
    stk[MAXN]; 
bool can(int i, int j) {  
    for (int k = 0; k < i; k++) { 
        if (queen[k] == j) return false;  
    }  
    for (int k = 0, l = 0; k < i; k++, l++) { 
        if (queen[k] - k == j - l && (k > 0 || l > 0)) return false;  
    }  
    for (int k = 0, l = 0; k < i; k++, l++) { 
        if (queen[k] + k == j + l && (k > 0 || l > 0)) return false;  
    }  
    return true;  
}  
void solve(int row) {  
    if (row == n) { 
        for (int i = 0; i < n; i++) {  
            cout << "Q ";  
        }  
        cout << endl;  
        return;  
    }  
    for (int i = 0; i < n; i++) {
        if (can(row, i)) {
            queen[row] = i;  
            stk[row] = col[i];
            col[i] = 1 - col[i]; 
            solve(row + 1); 
            col[i] = stk[row];
        }  
    }  
}  
int main() {  
    cin >> n; 
    solve(0);
    return 0;  
}